/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
 
class Solution {
public:
    vector<int> reversePrint(ListNode* head) {  
        stack<int> s;     //定义栈 s
        vector<int> print;   //容器

        ListNode* phead = head;
        while(phead != nullptr){     
            s.push(phead->val);    //先将 head链表中所有元素入栈
            phead = phead->next;
        }

        for(int i = 0; !s.empty(); i++){
            print.push_back(s.top());     //获取栈顶元素
            s.pop();    //出栈
         }
        return print;
    }

//递归
/*
    vector<int> reversePrint(ListNode* head) {
        if(head == nullptr){
            return{} ;       //返回的类型和函数类型一样 C++11
        }
        vector<int>print = reversePrint(head->next);
        print.push_back(head->val);
        return print; 
    }
 */

 /*
    vector<int>print;
     vector<int> reversePrint(ListNode* head) {

        if(head != nullptr){
           reversePrint(head->next);
            print.push_back(head->val);
        }
        return print; 
    }
 */
};